package des.wangku.operate.standard.swt.table;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import des.wangku.operate.standard.utls.UtilsDialogState;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableItem;

/**
 * 多条表格记录的整体弹出窗口
 * 
 * @author Sunjian
 * @version 1.0
 * @since jdk1.8
 */
public abstract class AbstractTablesEditDialog extends Dialog {

	/** 日志 */
	public static Logger logger = LoggerFactory.getLogger(AbstractTablesEditDialog.class);

	protected Shell parent;

	protected Shell shell = null;

	protected TableItem[] tableItems;

	public AbstractTablesEditDialog(Shell parent, int style) {
		super(parent, style);
		this.parent = parent;
		shell = new Shell(parent);
	}

	public AbstractTablesEditDialog(Shell parent, int style, TableItem... arrs) {
		super(parent, style);
		this.parent = parent;
		shell = new Shell(parent);
		this.tableItems = arrs;
	}
	public void setValue(TableItem... arrs) {
		this.tableItems = arrs;
	}

	/**
	 * 关闭
	 */
	public void close() {
		if (shell != null && !shell.isDisposed()) shell.close();
	}

	public abstract Object work();

	public Object open() {
		UtilsDialogState.changeDialogCenter(shell);
		work();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return null;
	}
}
